const connect = require('connect')
var createError = require('http-errors')
// var http = require('http')

var app = connect()

app.use('/index', function(req, res, next) {
  res.writeHead(200, 'OK', {
    //'content-type': 'text/plain;charset=utf-8' //纯文本
    'content-type': 'text/html;charset=utf-8',
  })
  res.write('<h1>你好，欢迎学习connect</h1>')
  res.end()
})

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404))
})

// error handler
app.use(function(err, req, res, next) {
  res.statusCode = 404
  res.end('Not Found')
})

// 两种方式监听指定端口
app.listen(3000) // 这种方式在connect里面调用了http.createServer方法

// http.createServer(app).listen(3000);